
# This file is executed on every boot (including wake-boot from deepsleep)
#import esp
#esp.osdebug(None)
import uos
#uos.dupterm(None, 1) # disable REPL on UART(0)
import gc
#import webrepl
#webrepl.start()
gc.collect()

from machine import Pin, Timer, RTC

import network, ntptime
def do_connect():
    import network
    wlan = network.WLAN(network.STA_IF)
    wlan.active(True)
    if not wlan.isconnected():
        print('connecting to network...')
        wlan.connect('SSID','PASSWORD')
        while not wlan.isconnected():
            pass
    print('network config:', wlan.ifconfig())
    rtc = RTC()
    ntptime.settime()
    print(rtc.datetime())

myperiod=0
pin2=Pin(2,Pin.OUT)
def blink(t):
  global myperiod
  if myperiod==100:
    do_connect()
  if myperiod%50==0:
    pin2.value(not pin2.value())
    #print(myperiod)
  myperiod+=1
  if myperiod==100000:
    myperiod=0

tim1=Timer(1)
tim1.init(period=100, mode=Timer.PERIODIC, callback=blink)
